package com.interest.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import redis.clients.jedis.Jedis;

import com.interest.model.IterUser;
import com.interest.service.TestService;

@Controller
@RequestMapping("/test")
public class TestController {
	
	@Autowired
	private TestService testService;
	
	
	/**
	 * 请求Redis返回数据
	 * */
	@ResponseBody 
	@RequestMapping("/setRedis.do")
	public List setRedis(){
		
		//连接Redis服务
		Jedis jedis = new Jedis("127.0.0.1");
		
	     // 获取存储的数据并输出
	     
	     jedis.del("testList");
	     
	     Long length = jedis.lpush("testList", "A");
	     length = jedis.lpush("testList", "b");
	     length = jedis.lpush("testList", "C");
	     
	     List<String> list = jedis.lrange("testList", 0, length);
	     
	     System.out.println(length);
	     
	     for(int i=0; i<list.size(); i++) {
	         System.out.println("Stored string in redis:: "+list.get(i));
	     }
		
		return null;
	}
	
	
	
	@ResponseBody
	@RequestMapping("/select.do")
	public List<IterUser> select(HttpServletRequest request){
		
		List<IterUser> userInfo = testService.select();
		
		System.out.println("----------------");
		System.out.println(userInfo);
		
		return userInfo;
	}
	
	
	@RequestMapping("/tiao.do")
	public String tiao(HttpServletRequest request){
		
		//List<Map<String, Object>> userInfo = testService.select();
		
		return "maps/gdMaps";
	}
	
}
